﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BUS;
using Entities;
using System.Text;

public partial class A_LetsDeal_quanlycanhan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }

    protected void load_data()
    {
        Tbl_KhachHang_Entities kh = Tbl_KhachHang_BUS.GetByUsername(Session["username"].ToString());
        lit_tendn.Text = kh.TaiKhoan;
        int len_mk = kh.MatKhau.Length;
        string mk = "";
        for (int i = 0; i < len_mk; i++)
        {
            mk = mk + "*";
        }
        lit_mk.Text = mk;
        HiddenField1.Value = kh.MatKhau;
        lit_sdtk.Text = kh.Sodutaikhoan.ToString();
        txt_hoten.Text = kh.HoTen;
        txt_diachi.Text = kh.DiaChi;
        txt_sdt.Text = kh.SDT;
        txt_email.Text = kh.Email;
    }

    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        if (txt_timkiem.Text != "")
        {
            Response.Redirect("~/A_LetsDeal/Default.aspx?tensanpham=" + txt_timkiem.Text);
        }
    }

    protected void bt_capnhat_Click(object sender, EventArgs e)
    {
        try
        {
            Tbl_KhachHang_Entities kh = new Tbl_KhachHang_Entities();
            kh.TaiKhoan = lit_tendn.Text;
            kh.MatKhau = HiddenField1.Value;
            kh.HoTen = txt_hoten.Text;
            kh.DiaChi = txt_diachi.Text;
            kh.SDT = txt_sdt.Text;
            kh.Email = txt_email.Text;
            kh.Sodutaikhoan = float.Parse(lit_sdtk.Text);
            Tbl_KhachHang_Entities kkhh = Tbl_KhachHang_BUS.GetByUsername(lit_tendn.Text);
            kh.STT = kkhh.STT;
            kh.LoaiTK = kkhh.LoaiTK;
            Tbl_KhachHang_BUS.Update(kh);
            Literal1.Text = "<font color='red'>Cập nhật thành công!</font>";
        }
        catch
        {
            Literal1.Text = "<font color='red'>Đã xảy ra lỗi!</font>";
        }
    }
}
